<?php  
class ControllerCommonColumnFindgift extends Controller {
	public function index() {
		$this->load->model('design/layout');
		$this->load->model('catalog/category');
		$this->load->model('catalog/product');
		$this->load->model('catalog/information');
		$this->language->load('product/search');
		// 3 Level Category Search
		$this->data['categories'] = array();
					
		$categories_1 = $this->model_catalog_category->getCategories(0);
		
		foreach ($categories_1 as $category_1) {
			$level_2_data = array();
			
			$categories_2 = $this->model_catalog_category->getCategories($category_1['category_id']);
			
			foreach ($categories_2 as $category_2) {
				$level_3_data = array();
				
				$categories_3 = $this->model_catalog_category->getCategories($category_2['category_id']);
				
				foreach ($categories_3 as $category_3) {
					$level_3_data[] = array(
						'category_id' => $category_3['category_id'],
						'name'        => $category_3['name'],
					);
				}
				
				$level_2_data[] = array(
					'category_id' => $category_2['category_id'],	
					'name'        => $category_2['name'],
					'children'    => $level_3_data
				);					
			}
			
			$this->data['categories'][] = array(
				'category_id' => $category_1['category_id'],
				'name'        => $category_1['name'],
				'children'    => $level_2_data
			);
		}
                 $this->data['FindGift'] = HTTP_SERVER . 'index.php?route=common/column_findgift';
              if (($this->request->server['REQUEST_METHOD'] == 'POST') ) {
                  if(isset($this->request->post['filter_category_id'])){
                      $SearchValue .= '&filter_category_id='.str_replace(' ', '+', $this->request->post['filter_category_id']);
                  }
                  if(isset($this->request->post['filter_name'])){
                      $SearchValue .= '&filter_name='.str_replace(' ', '+', $this->request->post['filter_name']);
                  }
                  if(isset($this->request->post['filter_tag'])){
                      $SearchValue .= '&filter_tag='.str_replace(' ', '+', $this->request->post['filter_tag']);
                  }
           
               $this->redirect(HTTP_SERVER . 'index.php?route=product/search' . $SearchValue);
            }
		if (isset($this->request->get['route'])) {
			$route = $this->request->get['route'];
		} else {
			$route = 'common/home';
		}
		
		
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/column_findgift.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/common/column_findgift.tpl';
		} else {
			$this->template = 'default/template/common/column_findgift.tpl';
		}
								
		$this->render();
	}
}
?>